package com.fhao.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.activemq.filter.function.makeListFunction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.fhao.feign.MemberServiceFeign;
import com.fuhao.api.entity.UserEntity;
import com.fuhao.base.ResponseBase;
import com.fuhao.constants.Constants;

@Controller
public class RegisterController {
	
	@Autowired
	private MemberServiceFeign memberFeign;
	//跳转到注册页面
	@RequestMapping(value="/register",method=RequestMethod.GET)
	public String register() {
		return "register";
	}
	//注册业务具体实现
	@RequestMapping(value="/register",method=RequestMethod.POST)
	public String registerPost(UserEntity userEntity,HttpServletRequest request) {
		//验证参数
		//调用会员注册接口

		ResponseBase regUser = memberFeign.regUser(userEntity);
		//失败，跳转失败页面
		if(regUser.getCode().equals(Constants.HTTP_RES_CODE_200_VALUE)) {
			request.setAttribute("error", "注册失败");
			return "register";
		}
		//成功
		return "login";
	}
	
}
